// $ANTLR 3.4 C:\\akamsi\\teaching\\Compilers_2011\\ANTLRStarterKit\\TreeExpr.g 2011-10-18 16:41:15

import org.antlr.runtime.*;
import java.util.Stack;
import java.util.List;
import java.util.ArrayList;

import org.antlr.runtime.debug.*;
import java.io.IOException;
import org.antlr.runtime.tree.*;


@SuppressWarnings({"all", "warnings", "unchecked"})
public class TreeExprParser extends DebugParser {
    public static final String[] tokenNames = new String[] {
        "<invalid>", "<EOR>", "<DOWN>", "<UP>", "ASSIGN", "ID", "INT", "MINUS", "MULT", "NEWLINE", "PLUS", "STATLIST", "WS", "'('", "')'"
    };

    public static final int EOF=-1;
    public static final int T__13=13;
    public static final int T__14=14;
    public static final int ASSIGN=4;
    public static final int ID=5;
    public static final int INT=6;
    public static final int MINUS=7;
    public static final int MULT=8;
    public static final int NEWLINE=9;
    public static final int PLUS=10;
    public static final int STATLIST=11;
    public static final int WS=12;

    // delegates
    public Parser[] getDelegates() {
        return new Parser[] {};
    }

    // delegators


public static final String[] ruleNames = new String[] {
    "invalidRule", "multExpr", "atom", "prog", "expr", "stat"
};

public static final boolean[] decisionCanBacktrack = new boolean[] {
    false, // invalid decision
    false, false, false, false, false, false
};

 
    public int ruleLevel = 0;
    public int getRuleLevel() { return ruleLevel; }
    public void incRuleLevel() { ruleLevel++; }
    public void decRuleLevel() { ruleLevel--; }
    public TreeExprParser(TokenStream input) {
        this(input, DebugEventSocketProxy.DEFAULT_DEBUGGER_PORT, new RecognizerSharedState());
    }
    public TreeExprParser(TokenStream input, int port, RecognizerSharedState state) {
        super(input, state);
        DebugEventSocketProxy proxy =
            new DebugEventSocketProxy(this,port,adaptor);
        setDebugListener(proxy);
        setTokenStream(new DebugTokenStream(input,proxy));
        try {
            proxy.handshake();
        }
        catch (IOException ioe) {
            reportError(ioe);
        }
        TreeAdaptor adap = new CommonTreeAdaptor();
        setTreeAdaptor(adap);
        proxy.setTreeAdaptor(adap);
    }

public TreeExprParser(TokenStream input, DebugEventListener dbg) {
    super(input, dbg);
     
    TreeAdaptor adap = new CommonTreeAdaptor();
    setTreeAdaptor(adap);


}

protected boolean evalPredicate(boolean result, String predicate) {
    dbg.semanticPredicate(result, predicate);
    return result;
}

protected DebugTreeAdaptor adaptor;
public void setTreeAdaptor(TreeAdaptor adaptor) {
    this.adaptor = new DebugTreeAdaptor(dbg,adaptor);


}
public TreeAdaptor getTreeAdaptor() {
    return adaptor;
}

    public String[] getTokenNames() { return TreeExprParser.tokenNames; }
    public String getGrammarFileName() { return "C:\\akamsi\\teaching\\Compilers_2011\\ANTLRStarterKit\\TreeExpr.g"; }





    public static class prog_return extends ParserRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };


    // $ANTLR start "prog"
    // C:\\akamsi\\teaching\\Compilers_2011\\ANTLRStarterKit\\TreeExpr.g:22:1: prog : ( stat )+ -> ^( STATLIST ( stat )+ ) ;
    public final TreeExprParser.prog_return prog() throws RecognitionException {
        TreeExprParser.prog_return retval = new TreeExprParser.prog_return();
        retval.start = input.LT(1);


        CommonTree root_0 = null;

        TreeExprParser.stat_return stat1 =null;


        RewriteRuleSubtreeStream stream_stat=new RewriteRuleSubtreeStream(adaptor,"rule stat");
        try { dbg.enterRule(getGrammarFileName(), "prog");
        if ( getRuleLevel()==0 ) {dbg.commence();}
        incRuleLevel();
        dbg.location(22, 0);

        try {
            // C:\\akamsi\\teaching\\Compilers_2011\\ANTLRStarterKit\\TreeExpr.g:22:5: ( ( stat )+ -> ^( STATLIST ( stat )+ ) )
            dbg.enterAlt(1);

            // C:\\akamsi\\teaching\\Compilers_2011\\ANTLRStarterKit\\TreeExpr.g:22:9: ( stat )+
            {
            dbg.location(22,9);
            // C:\\akamsi\\teaching\\Compilers_2011\\ANTLRStarterKit\\TreeExpr.g:22:9: ( stat )+
            int cnt1=0;
            try { dbg.enterSubRule(1);

            loop1:
            do {
                int alt1=2;
                try { dbg.enterDecision(1, decisionCanBacktrack[1]);

                int LA1_0 = input.LA(1);

                if ( ((LA1_0 >= ID && LA1_0 <= INT)||LA1_0==NEWLINE||LA1_0==13) ) {
                    alt1=1;
                }


                } finally {dbg.exitDecision(1);}

                switch (alt1) {
            	case 1 :
            	    dbg.enterAlt(1);

            	    // C:\\akamsi\\teaching\\Compilers_2011\\ANTLRStarterKit\\TreeExpr.g:22:11: stat
            	    {
            	    dbg.location(22,11);
            	    pushFollow(FOLLOW_stat_in_prog134);
            	    stat1=stat();

            	    state._fsp--;

            	    stream_stat.add(stat1.getTree());
            	    dbg.location(22,16);
            	    System.out.println((stat1!=null?((CommonTree)stat1.tree):null).toStringTree());

            	    }
            	    break;

            	default :
            	    if ( cnt1 >= 1 ) break loop1;
                        EarlyExitException eee =
                            new EarlyExitException(1, input);
                        dbg.recognitionException(eee);

                        throw eee;
                }
                cnt1++;
            } while (true);
            } finally {dbg.exitSubRule(1);}


            // AST REWRITE
            // elements: stat
            // token labels: 
            // rule labels: retval
            // token list labels: 
            // rule list labels: 
            // wildcard labels: 
            retval.tree = root_0;
            RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

            root_0 = (CommonTree)adaptor.nil();
            // 22:68: -> ^( STATLIST ( stat )+ )
            {
                dbg.location(22,71);
                // C:\\akamsi\\teaching\\Compilers_2011\\ANTLRStarterKit\\TreeExpr.g:22:71: ^( STATLIST ( stat )+ )
                {
                CommonTree root_1 = (CommonTree)adaptor.nil();
                dbg.location(22,73);
                root_1 = (CommonTree)adaptor.becomeRoot(
                (CommonTree)adaptor.create(STATLIST, "STATLIST")
                , root_1);

                dbg.location(22,82);
                if ( !(stream_stat.hasNext()) ) {
                    throw new RewriteEarlyExitException();
                }
                while ( stream_stat.hasNext() ) {
                    dbg.location(22,83);
                    adaptor.addChild(root_1, stream_stat.nextTree());

                }
                stream_stat.reset();

                adaptor.addChild(root_0, root_1);
                }

            }


            retval.tree = root_0;

            }

            retval.stop = input.LT(-1);


            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (CommonTree)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }

        finally {
        	// do for sure before leaving
        }
        dbg.location(22, 90);

        }
        finally {
            dbg.exitRule(getGrammarFileName(), "prog");
            decRuleLevel();
            if ( getRuleLevel()==0 ) {dbg.terminate();}
        }

        return retval;
    }
    // $ANTLR end "prog"


    public static class stat_return extends ParserRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };


    // $ANTLR start "stat"
    // C:\\akamsi\\teaching\\Compilers_2011\\ANTLRStarterKit\\TreeExpr.g:24:1: stat : ( expr NEWLINE -> expr | ID ASSIGN expr NEWLINE -> ^( ASSIGN ID expr ) | NEWLINE ->);
    public final TreeExprParser.stat_return stat() throws RecognitionException {
        TreeExprParser.stat_return retval = new TreeExprParser.stat_return();
        retval.start = input.LT(1);


        CommonTree root_0 = null;

        Token NEWLINE3=null;
        Token ID4=null;
        Token ASSIGN5=null;
        Token NEWLINE7=null;
        Token NEWLINE8=null;
        TreeExprParser.expr_return expr2 =null;

        TreeExprParser.expr_return expr6 =null;


        CommonTree NEWLINE3_tree=null;
        CommonTree ID4_tree=null;
        CommonTree ASSIGN5_tree=null;
        CommonTree NEWLINE7_tree=null;
        CommonTree NEWLINE8_tree=null;
        RewriteRuleTokenStream stream_NEWLINE=new RewriteRuleTokenStream(adaptor,"token NEWLINE");
        RewriteRuleTokenStream stream_ID=new RewriteRuleTokenStream(adaptor,"token ID");
        RewriteRuleTokenStream stream_ASSIGN=new RewriteRuleTokenStream(adaptor,"token ASSIGN");
        RewriteRuleSubtreeStream stream_expr=new RewriteRuleSubtreeStream(adaptor,"rule expr");
        try { dbg.enterRule(getGrammarFileName(), "stat");
        if ( getRuleLevel()==0 ) {dbg.commence();}
        incRuleLevel();
        dbg.location(24, 0);

        try {
            // C:\\akamsi\\teaching\\Compilers_2011\\ANTLRStarterKit\\TreeExpr.g:24:5: ( expr NEWLINE -> expr | ID ASSIGN expr NEWLINE -> ^( ASSIGN ID expr ) | NEWLINE ->)
            int alt2=3;
            try { dbg.enterDecision(2, decisionCanBacktrack[2]);

            switch ( input.LA(1) ) {
            case INT:
            case 13:
                {
                alt2=1;
                }
                break;
            case ID:
                {
                int LA2_2 = input.LA(2);

                if ( (LA2_2==ASSIGN) ) {
                    alt2=2;
                }
                else if ( ((LA2_2 >= MINUS && LA2_2 <= PLUS)) ) {
                    alt2=1;
                }
                else {
                    NoViableAltException nvae =
                        new NoViableAltException("", 2, 2, input);

                    dbg.recognitionException(nvae);
                    throw nvae;

                }
                }
                break;
            case NEWLINE:
                {
                alt2=3;
                }
                break;
            default:
                NoViableAltException nvae =
                    new NoViableAltException("", 2, 0, input);

                dbg.recognitionException(nvae);
                throw nvae;

            }

            } finally {dbg.exitDecision(2);}

            switch (alt2) {
                case 1 :
                    dbg.enterAlt(1);

                    // C:\\akamsi\\teaching\\Compilers_2011\\ANTLRStarterKit\\TreeExpr.g:24:9: expr NEWLINE
                    {
                    dbg.location(24,9);
                    pushFollow(FOLLOW_expr_in_stat160);
                    expr2=expr();

                    state._fsp--;

                    stream_expr.add(expr2.getTree());
                    dbg.location(24,14);
                    NEWLINE3=(Token)match(input,NEWLINE,FOLLOW_NEWLINE_in_stat162);  
                    stream_NEWLINE.add(NEWLINE3);


                    // AST REWRITE
                    // elements: expr
                    // token labels: 
                    // rule labels: retval
                    // token list labels: 
                    // rule list labels: 
                    // wildcard labels: 
                    retval.tree = root_0;
                    RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

                    root_0 = (CommonTree)adaptor.nil();
                    // 24:29: -> expr
                    {
                        dbg.location(24,32);
                        adaptor.addChild(root_0, stream_expr.nextTree());

                    }


                    retval.tree = root_0;

                    }
                    break;
                case 2 :
                    dbg.enterAlt(2);

                    // C:\\akamsi\\teaching\\Compilers_2011\\ANTLRStarterKit\\TreeExpr.g:25:9: ID ASSIGN expr NEWLINE
                    {
                    dbg.location(25,9);
                    ID4=(Token)match(input,ID,FOLLOW_ID_in_stat183);  
                    stream_ID.add(ID4);

                    dbg.location(25,12);
                    ASSIGN5=(Token)match(input,ASSIGN,FOLLOW_ASSIGN_in_stat185);  
                    stream_ASSIGN.add(ASSIGN5);

                    dbg.location(25,19);
                    pushFollow(FOLLOW_expr_in_stat187);
                    expr6=expr();

                    state._fsp--;

                    stream_expr.add(expr6.getTree());
                    dbg.location(25,24);
                    NEWLINE7=(Token)match(input,NEWLINE,FOLLOW_NEWLINE_in_stat189);  
                    stream_NEWLINE.add(NEWLINE7);


                    // AST REWRITE
                    // elements: expr, ASSIGN, ID
                    // token labels: 
                    // rule labels: retval
                    // token list labels: 
                    // rule list labels: 
                    // wildcard labels: 
                    retval.tree = root_0;
                    RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

                    root_0 = (CommonTree)adaptor.nil();
                    // 25:32: -> ^( ASSIGN ID expr )
                    {
                        dbg.location(25,35);
                        // C:\\akamsi\\teaching\\Compilers_2011\\ANTLRStarterKit\\TreeExpr.g:25:35: ^( ASSIGN ID expr )
                        {
                        CommonTree root_1 = (CommonTree)adaptor.nil();
                        dbg.location(25,37);
                        root_1 = (CommonTree)adaptor.becomeRoot(
                        stream_ASSIGN.nextNode()
                        , root_1);

                        dbg.location(25,44);
                        adaptor.addChild(root_1, 
                        stream_ID.nextNode()
                        );
                        dbg.location(25,47);
                        adaptor.addChild(root_1, stream_expr.nextTree());

                        adaptor.addChild(root_0, root_1);
                        }

                    }


                    retval.tree = root_0;

                    }
                    break;
                case 3 :
                    dbg.enterAlt(3);

                    // C:\\akamsi\\teaching\\Compilers_2011\\ANTLRStarterKit\\TreeExpr.g:26:9: NEWLINE
                    {
                    dbg.location(26,9);
                    NEWLINE8=(Token)match(input,NEWLINE,FOLLOW_NEWLINE_in_stat209);  
                    stream_NEWLINE.add(NEWLINE8);


                    // AST REWRITE
                    // elements: 
                    // token labels: 
                    // rule labels: retval
                    // token list labels: 
                    // rule list labels: 
                    // wildcard labels: 
                    retval.tree = root_0;
                    RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

                    root_0 = (CommonTree)adaptor.nil();
                    // 26:29: ->
                    {
                        dbg.location(27,5);
                        root_0 = null;
                    }


                    retval.tree = root_0;

                    }
                    break;

            }
            retval.stop = input.LT(-1);


            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (CommonTree)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }

        finally {
        	// do for sure before leaving
        }
        dbg.location(27, 4);

        }
        finally {
            dbg.exitRule(getGrammarFileName(), "stat");
            decRuleLevel();
            if ( getRuleLevel()==0 ) {dbg.terminate();}
        }

        return retval;
    }
    // $ANTLR end "stat"


    public static class expr_return extends ParserRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };


    // $ANTLR start "expr"
    // C:\\akamsi\\teaching\\Compilers_2011\\ANTLRStarterKit\\TreeExpr.g:29:1: expr : multExpr ( ( PLUS ^| MINUS ^) multExpr )* ;
    public final TreeExprParser.expr_return expr() throws RecognitionException {
        TreeExprParser.expr_return retval = new TreeExprParser.expr_return();
        retval.start = input.LT(1);


        CommonTree root_0 = null;

        Token PLUS10=null;
        Token MINUS11=null;
        TreeExprParser.multExpr_return multExpr9 =null;

        TreeExprParser.multExpr_return multExpr12 =null;


        CommonTree PLUS10_tree=null;
        CommonTree MINUS11_tree=null;

        try { dbg.enterRule(getGrammarFileName(), "expr");
        if ( getRuleLevel()==0 ) {dbg.commence();}
        incRuleLevel();
        dbg.location(29, 0);

        try {
            // C:\\akamsi\\teaching\\Compilers_2011\\ANTLRStarterKit\\TreeExpr.g:29:5: ( multExpr ( ( PLUS ^| MINUS ^) multExpr )* )
            dbg.enterAlt(1);

            // C:\\akamsi\\teaching\\Compilers_2011\\ANTLRStarterKit\\TreeExpr.g:29:9: multExpr ( ( PLUS ^| MINUS ^) multExpr )*
            {
            root_0 = (CommonTree)adaptor.nil();


            dbg.location(29,9);
            pushFollow(FOLLOW_multExpr_in_expr237);
            multExpr9=multExpr();

            state._fsp--;

            adaptor.addChild(root_0, multExpr9.getTree());
            dbg.location(29,18);
            // C:\\akamsi\\teaching\\Compilers_2011\\ANTLRStarterKit\\TreeExpr.g:29:18: ( ( PLUS ^| MINUS ^) multExpr )*
            try { dbg.enterSubRule(4);

            loop4:
            do {
                int alt4=2;
                try { dbg.enterDecision(4, decisionCanBacktrack[4]);

                int LA4_0 = input.LA(1);

                if ( (LA4_0==MINUS||LA4_0==PLUS) ) {
                    alt4=1;
                }


                } finally {dbg.exitDecision(4);}

                switch (alt4) {
            	case 1 :
            	    dbg.enterAlt(1);

            	    // C:\\akamsi\\teaching\\Compilers_2011\\ANTLRStarterKit\\TreeExpr.g:29:19: ( PLUS ^| MINUS ^) multExpr
            	    {
            	    dbg.location(29,19);
            	    // C:\\akamsi\\teaching\\Compilers_2011\\ANTLRStarterKit\\TreeExpr.g:29:19: ( PLUS ^| MINUS ^)
            	    int alt3=2;
            	    try { dbg.enterSubRule(3);
            	    try { dbg.enterDecision(3, decisionCanBacktrack[3]);

            	    int LA3_0 = input.LA(1);

            	    if ( (LA3_0==PLUS) ) {
            	        alt3=1;
            	    }
            	    else if ( (LA3_0==MINUS) ) {
            	        alt3=2;
            	    }
            	    else {
            	        NoViableAltException nvae =
            	            new NoViableAltException("", 3, 0, input);

            	        dbg.recognitionException(nvae);
            	        throw nvae;

            	    }
            	    } finally {dbg.exitDecision(3);}

            	    switch (alt3) {
            	        case 1 :
            	            dbg.enterAlt(1);

            	            // C:\\akamsi\\teaching\\Compilers_2011\\ANTLRStarterKit\\TreeExpr.g:29:20: PLUS ^
            	            {
            	            dbg.location(29,24);
            	            PLUS10=(Token)match(input,PLUS,FOLLOW_PLUS_in_expr241); 
            	            PLUS10_tree = 
            	            (CommonTree)adaptor.create(PLUS10)
            	            ;
            	            root_0 = (CommonTree)adaptor.becomeRoot(PLUS10_tree, root_0);


            	            }
            	            break;
            	        case 2 :
            	            dbg.enterAlt(2);

            	            // C:\\akamsi\\teaching\\Compilers_2011\\ANTLRStarterKit\\TreeExpr.g:29:26: MINUS ^
            	            {
            	            dbg.location(29,31);
            	            MINUS11=(Token)match(input,MINUS,FOLLOW_MINUS_in_expr244); 
            	            MINUS11_tree = 
            	            (CommonTree)adaptor.create(MINUS11)
            	            ;
            	            root_0 = (CommonTree)adaptor.becomeRoot(MINUS11_tree, root_0);


            	            }
            	            break;

            	    }
            	    } finally {dbg.exitSubRule(3);}

            	    dbg.location(29,34);
            	    pushFollow(FOLLOW_multExpr_in_expr248);
            	    multExpr12=multExpr();

            	    state._fsp--;

            	    adaptor.addChild(root_0, multExpr12.getTree());

            	    }
            	    break;

            	default :
            	    break loop4;
                }
            } while (true);
            } finally {dbg.exitSubRule(4);}


            }

            retval.stop = input.LT(-1);


            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (CommonTree)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }

        finally {
        	// do for sure before leaving
        }
        dbg.location(30, 4);

        }
        finally {
            dbg.exitRule(getGrammarFileName(), "expr");
            decRuleLevel();
            if ( getRuleLevel()==0 ) {dbg.terminate();}
        }

        return retval;
    }
    // $ANTLR end "expr"


    public static class multExpr_return extends ParserRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };


    // $ANTLR start "multExpr"
    // C:\\akamsi\\teaching\\Compilers_2011\\ANTLRStarterKit\\TreeExpr.g:32:1: multExpr : atom ( MULT ^ atom )* ;
    public final TreeExprParser.multExpr_return multExpr() throws RecognitionException {
        TreeExprParser.multExpr_return retval = new TreeExprParser.multExpr_return();
        retval.start = input.LT(1);


        CommonTree root_0 = null;

        Token MULT14=null;
        TreeExprParser.atom_return atom13 =null;

        TreeExprParser.atom_return atom15 =null;


        CommonTree MULT14_tree=null;

        try { dbg.enterRule(getGrammarFileName(), "multExpr");
        if ( getRuleLevel()==0 ) {dbg.commence();}
        incRuleLevel();
        dbg.location(32, 0);

        try {
            // C:\\akamsi\\teaching\\Compilers_2011\\ANTLRStarterKit\\TreeExpr.g:33:5: ( atom ( MULT ^ atom )* )
            dbg.enterAlt(1);

            // C:\\akamsi\\teaching\\Compilers_2011\\ANTLRStarterKit\\TreeExpr.g:33:9: atom ( MULT ^ atom )*
            {
            root_0 = (CommonTree)adaptor.nil();


            dbg.location(33,9);
            pushFollow(FOLLOW_atom_in_multExpr270);
            atom13=atom();

            state._fsp--;

            adaptor.addChild(root_0, atom13.getTree());
            dbg.location(33,14);
            // C:\\akamsi\\teaching\\Compilers_2011\\ANTLRStarterKit\\TreeExpr.g:33:14: ( MULT ^ atom )*
            try { dbg.enterSubRule(5);

            loop5:
            do {
                int alt5=2;
                try { dbg.enterDecision(5, decisionCanBacktrack[5]);

                int LA5_0 = input.LA(1);

                if ( (LA5_0==MULT) ) {
                    alt5=1;
                }


                } finally {dbg.exitDecision(5);}

                switch (alt5) {
            	case 1 :
            	    dbg.enterAlt(1);

            	    // C:\\akamsi\\teaching\\Compilers_2011\\ANTLRStarterKit\\TreeExpr.g:33:15: MULT ^ atom
            	    {
            	    dbg.location(33,19);
            	    MULT14=(Token)match(input,MULT,FOLLOW_MULT_in_multExpr273); 
            	    MULT14_tree = 
            	    (CommonTree)adaptor.create(MULT14)
            	    ;
            	    root_0 = (CommonTree)adaptor.becomeRoot(MULT14_tree, root_0);

            	    dbg.location(33,21);
            	    pushFollow(FOLLOW_atom_in_multExpr276);
            	    atom15=atom();

            	    state._fsp--;

            	    adaptor.addChild(root_0, atom15.getTree());

            	    }
            	    break;

            	default :
            	    break loop5;
                }
            } while (true);
            } finally {dbg.exitSubRule(5);}


            }

            retval.stop = input.LT(-1);


            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (CommonTree)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }

        finally {
        	// do for sure before leaving
        }
        dbg.location(34, 4);

        }
        finally {
            dbg.exitRule(getGrammarFileName(), "multExpr");
            decRuleLevel();
            if ( getRuleLevel()==0 ) {dbg.terminate();}
        }

        return retval;
    }
    // $ANTLR end "multExpr"


    public static class atom_return extends ParserRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };


    // $ANTLR start "atom"
    // C:\\akamsi\\teaching\\Compilers_2011\\ANTLRStarterKit\\TreeExpr.g:36:1: atom : ( INT | ID | '(' ! expr ')' !);
    public final TreeExprParser.atom_return atom() throws RecognitionException {
        TreeExprParser.atom_return retval = new TreeExprParser.atom_return();
        retval.start = input.LT(1);


        CommonTree root_0 = null;

        Token INT16=null;
        Token ID17=null;
        Token char_literal18=null;
        Token char_literal20=null;
        TreeExprParser.expr_return expr19 =null;


        CommonTree INT16_tree=null;
        CommonTree ID17_tree=null;
        CommonTree char_literal18_tree=null;
        CommonTree char_literal20_tree=null;

        try { dbg.enterRule(getGrammarFileName(), "atom");
        if ( getRuleLevel()==0 ) {dbg.commence();}
        incRuleLevel();
        dbg.location(36, 0);

        try {
            // C:\\akamsi\\teaching\\Compilers_2011\\ANTLRStarterKit\\TreeExpr.g:36:5: ( INT | ID | '(' ! expr ')' !)
            int alt6=3;
            try { dbg.enterDecision(6, decisionCanBacktrack[6]);

            switch ( input.LA(1) ) {
            case INT:
                {
                alt6=1;
                }
                break;
            case ID:
                {
                alt6=2;
                }
                break;
            case 13:
                {
                alt6=3;
                }
                break;
            default:
                NoViableAltException nvae =
                    new NoViableAltException("", 6, 0, input);

                dbg.recognitionException(nvae);
                throw nvae;

            }

            } finally {dbg.exitDecision(6);}

            switch (alt6) {
                case 1 :
                    dbg.enterAlt(1);

                    // C:\\akamsi\\teaching\\Compilers_2011\\ANTLRStarterKit\\TreeExpr.g:36:9: INT
                    {
                    root_0 = (CommonTree)adaptor.nil();


                    dbg.location(36,9);
                    INT16=(Token)match(input,INT,FOLLOW_INT_in_atom293); 
                    INT16_tree = 
                    (CommonTree)adaptor.create(INT16)
                    ;
                    adaptor.addChild(root_0, INT16_tree);


                    }
                    break;
                case 2 :
                    dbg.enterAlt(2);

                    // C:\\akamsi\\teaching\\Compilers_2011\\ANTLRStarterKit\\TreeExpr.g:37:9: ID
                    {
                    root_0 = (CommonTree)adaptor.nil();


                    dbg.location(37,9);
                    ID17=(Token)match(input,ID,FOLLOW_ID_in_atom304); 
                    ID17_tree = 
                    (CommonTree)adaptor.create(ID17)
                    ;
                    adaptor.addChild(root_0, ID17_tree);


                    }
                    break;
                case 3 :
                    dbg.enterAlt(3);

                    // C:\\akamsi\\teaching\\Compilers_2011\\ANTLRStarterKit\\TreeExpr.g:38:9: '(' ! expr ')' !
                    {
                    root_0 = (CommonTree)adaptor.nil();


                    dbg.location(38,12);
                    char_literal18=(Token)match(input,13,FOLLOW_13_in_atom314); 
                    dbg.location(38,14);
                    pushFollow(FOLLOW_expr_in_atom317);
                    expr19=expr();

                    state._fsp--;

                    adaptor.addChild(root_0, expr19.getTree());
                    dbg.location(38,22);
                    char_literal20=(Token)match(input,14,FOLLOW_14_in_atom319); 

                    }
                    break;

            }
            retval.stop = input.LT(-1);


            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (CommonTree)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }

        finally {
        	// do for sure before leaving
        }
        dbg.location(39, 4);

        }
        finally {
            dbg.exitRule(getGrammarFileName(), "atom");
            decRuleLevel();
            if ( getRuleLevel()==0 ) {dbg.terminate();}
        }

        return retval;
    }
    // $ANTLR end "atom"

    // Delegated rules


 

    public static final BitSet FOLLOW_stat_in_prog134 = new BitSet(new long[]{0x0000000000002262L});
    public static final BitSet FOLLOW_expr_in_stat160 = new BitSet(new long[]{0x0000000000000200L});
    public static final BitSet FOLLOW_NEWLINE_in_stat162 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_ID_in_stat183 = new BitSet(new long[]{0x0000000000000010L});
    public static final BitSet FOLLOW_ASSIGN_in_stat185 = new BitSet(new long[]{0x0000000000002060L});
    public static final BitSet FOLLOW_expr_in_stat187 = new BitSet(new long[]{0x0000000000000200L});
    public static final BitSet FOLLOW_NEWLINE_in_stat189 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_NEWLINE_in_stat209 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_multExpr_in_expr237 = new BitSet(new long[]{0x0000000000000482L});
    public static final BitSet FOLLOW_PLUS_in_expr241 = new BitSet(new long[]{0x0000000000002060L});
    public static final BitSet FOLLOW_MINUS_in_expr244 = new BitSet(new long[]{0x0000000000002060L});
    public static final BitSet FOLLOW_multExpr_in_expr248 = new BitSet(new long[]{0x0000000000000482L});
    public static final BitSet FOLLOW_atom_in_multExpr270 = new BitSet(new long[]{0x0000000000000102L});
    public static final BitSet FOLLOW_MULT_in_multExpr273 = new BitSet(new long[]{0x0000000000002060L});
    public static final BitSet FOLLOW_atom_in_multExpr276 = new BitSet(new long[]{0x0000000000000102L});
    public static final BitSet FOLLOW_INT_in_atom293 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_ID_in_atom304 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_13_in_atom314 = new BitSet(new long[]{0x0000000000002060L});
    public static final BitSet FOLLOW_expr_in_atom317 = new BitSet(new long[]{0x0000000000004000L});
    public static final BitSet FOLLOW_14_in_atom319 = new BitSet(new long[]{0x0000000000000002L});

}